<?php
namespace app\admin\controller;

use app\common\model\Order   as GamePayLogModel;
use app\common\model\Gamelist   as GameListModel;
use app\common\model\Gameagent  as GameAgentModel;
use app\common\model\Player as PlayerModel;
use app\common\controller\AdminBase;
use think\Config;
use think\Db;

/**
 * 玩家管理
 * Class AdminUser
 * @package app\admin\controller
 */
class Order extends AdminBase
{
    
    protected function _initialize()
    {
        parent::_initialize();
    }
    

    /**
     * 充值记录
     * @param string $keyword
     * @param int    $page
     * @return mixed
     */
    public function index()
    {
		/* 查询条件初始化 */
    	$data = input();
        $map  = [];
		$game_list =[];
        $page = $data['page'] ?? 1;
        if(!empty($data['keyword'])){
		    $map[]  = ['a.uid|a.order_no','like', '%'.$data['keyword'].'%'];
        }
        $join = 'Player';
        if(!empty($data['account'])){
            $map[]  = ['c.account','like', '%'.$data['account'].'%'];
        }
        if(!empty($data['game'])){
            $map[]   = ['a.gid','=' ,$data['game']];
        }else{
		    $data['game']   = null;
		}
        if(isset($data['cid']) && $data['cid']!=""){
            $map[]  = ['a.cid','=',$data['cid']];
        }

        
        if(!empty($data['status'])){
            switch ($data['status']){
                case 1:
                    $map[]  = ['a.order_status','=',$data['status']-1];
                break;
                case 2:
                    $map[]  = ['a.order_status','>',0];
                    break;
                case 3:
                    $map[]  = ['a.order_status','=',$data['status']];
                break;
                case 4:
                    $map[]  = ['a.order_status','=',$data['status']];
                    break;
            }

        }else{
           $data['status']    = null;
        }

        if(!empty($data['endtime']) && stripos($data['endtime'],"00:00:00")){
            $data['endtime'] =  substr($data['endtime'],0,10)." 23:59:59";
            input('endtime',$data['endtime']);
        }
        if (!empty($data['starttime']) && !empty($data['endtime'])) {
            $map[]= ['a.pay_time','between time',[$data['starttime'],$data['endtime']]];
        }elseif (!empty($data['starttime'])) {
            $map[] = ['a.pay_time','>=',$data['starttime']];
        }elseif (!empty($data['endtime'])) {
            $map[] = ['a.pay_time','<=',$data['endtime']];
        }
		$field = 'a.*,b.name,c.account,d.username as aname,d.nickname';
		//$pay_list = GamePModel::alias('a')->join('Gamelist b','b.id = a.gid','left')->join('Gamearea c','c.id = a.sid','left')->where($map)->field($field)->order('a.id DESC')->paginate(15, false, ['page' => $page,'query' =>request()->param()]);
		$pay_list = GamePayLogModel::alias('a')
            ->join('Gamelist b','b.id = a.gid','left')
            ->join('Player c','c.id = a.uid','left')
            ->join('Channel d','d.id = a.cid','left')
            ->where($map)->field($field)
            ->order('a.id DESC')
            ->paginate(15, false, ['page' => $page,'query' =>request()->param()]);
        $this->assign('pay_list',$pay_list);
        $this->assign('data',$data);
        return $this->fetch();
    }

}